<?php
declare (strict_types=1);

namespace app\common\validate;

use app\common\service\ResponseService;
use app\Request;
use think\Validate;

class BaseValidate extends Validate
{
    use ResponseService;

    public function __construct(Request $request)
    {
        parent::__construct();

        // 方法名，一个方法一个场景
        $action = $request->action(true);
        // 判断该值是否存在场景中
        if (!array_key_exists($action, $this->scene)) {
            return true;
        }
        // 验证数据
        if (!$this->scene($action)->check($request->param())) {
            $this->responseException($this->getError());
        }
    }
}